<template>
  <div class="execution">
    <basic-container>
      <avue-crud ref="crud"
                 :page.sync="page"
                 :data="tableData"
                 :permission="getPermission"
                 :table-loading="tableLoading"
                 :option="tableOption"
                 v-model="form"
                 @on-load="getPage"
                 @refresh-change="refreshChange"
                 @row-update="handleUpdate"
                 @row-save="handleSave"
                 @row-del="handleDel"
                 @sort-change="sortChange"
                 @search-change="searchChange">
        <!--银行卡信息-->
        <template slot-scope="scope" slot="cardHolder">
          <div style="text-align: left">
            <div class="grid-content">持卡人：{{scope.row.cardHolder || ''}}</div>
            <div class="grid-content">开户行：{{scope.row.cardBank || ''}}</div>
            <div class="grid-content">卡号：{{scope.row.cardId || ''}}</div>
          </div>
        </template>
        <!--状态-->
        <template slot-scope="scope" slot="status">
          <el-tag :type="scope.row.status=='0' ? 'info' : (scope.row.status=='1' ? 'success' : 'danger')" effect="dark" size="mini">
            {{scope.row.status == '0' ? '待审核' : (scope.row.status == '1' ? '已打款' : '驳回')}}
          </el-tag>
        </template>
        <!--审核信息-->
        <template slot-scope="scope" slot="reviewer">
          <div style="text-align: left">
            <div class="grid-content">审核人：{{scope.row.reviewer || ''}}</div>
            <div class="grid-content">审核时间：{{scope.row.reviewTime || ''}}</div>
            <div class="grid-content">审核说明：{{scope.row.remark || ''}}</div>
          </div>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
  import {getPage, getObj, addObj, reviewer, delObj} from '@/api/mall/providerwithdraw'
  import {tableOption} from '@/const/crud/mall/providerwithdraw'
  import {mapGetters} from 'vuex'

  export default {
    name: 'providerwithdraw',
    components: {},
    data() {
      return {
        form: {},
        tableData: [],
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20, // 每页显示多少条
          ascs: [],//升序字段
          descs: []//降序字段
        },
        paramsSearch: {},
        tableLoading: false,
        tableOption: tableOption
      }
    },
    created() {
    },
    mounted: function () {
    },
    computed: {
      ...mapGetters(['permissions']),
      permissionList() {
        return {
          addBtn: !!this.permissions['mall:providerwithdraw:add'],
          delBtn: !!this.permissions['mall:providerwithdraw:del'],
          editBtn: !!this.permissions['mall:providerwithdraw:edit'],
          viewBtn: !!this.permissions['mall:providerwithdraw:get']
        };
      }
    },
    methods: {
      getPermission (key, row, index) {
        if (key === 'editBtn' && row.status === '1') {
          return false;
        }
        return true;
      },
      searchChange(params, done) {
        params = this.filterForm(params)
        this.paramsSearch = params
        this.page.currentPage = 1
        this.getPage(this.page, params)
        done()
      },
      sortChange(val) {
        let prop = val.prop ? val.prop.replace(/([A-Z])/g, "_$1").toLowerCase() : ''
        if (val.order == 'ascending') {
          this.page.descs = []
          this.page.ascs = prop
        } else if (val.order == 'descending') {
          this.page.ascs = []
          this.page.descs = prop
        } else {
          this.page.ascs = []
          this.page.descs = []
        }
        this.getPage(this.page)
      },
      getPage(page, params) {
        this.tableLoading = true
        getPage(Object.assign({
          current: page.currentPage,
          size: page.pageSize,
          descs: this.page.descs,
          ascs: this.page.ascs,
        }, params, this.paramsSearch)).then(response => {
          let tableData = response.data.data.records
          tableData.forEach(function (item, index) {
            item.picUrl = [item.picUrl]
          })
          this.tableData = tableData
          this.page.total = response.data.data.total
          this.page.currentPage = page.currentPage
          this.page.pageSize = page.pageSize
          this.tableLoading = false
        }).catch(() => {
          this.tableLoading = false
        })
      },
      /**
       * @title 数据删除
       * @param row 为当前的数据
       * @param index 为当前删除数据的行数
       *
       **/
      handleDel: function (row, index) {
        let _this = this
        this.$confirm('是否确认删除此数据', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function () {
          return delObj(row.id)
        }).then(data => {
          _this.$message({
            showClose: true,
            message: '删除成功',
            type: 'success'
          })
          this.getPage(this.page)
        }).catch(function (err) {
        })
      },
      /**
       * @title 审核
       * @param row 为当前的数据
       * @param index 为当前更新数据的行数
       * @param done 为表单关闭函数
       *
       **/
      handleUpdate: function (row, index, done, loading) {
        reviewer(row).then(response => {
          this.$message({
            showClose: true,
            message: '操作成功',
            type: 'success'
          })
          done()
          this.getPage(this.page)
        }).catch(() => {
          loading()
        })
      },
      /**
       * @title 数据添加
       * @param row 为当前的数据
       * @param done 为表单关闭函数
       *
       **/
      handleSave: function (row, done, loading) {
        addObj(row).then(response => {
          this.$message({
            showClose: true,
            message: '添加成功',
            type: 'success'
          })
          done()
          this.getPage(this.page)
        }).catch(() => {
          loading()
        })
      },
      /**
       * 刷新回调
       */
      refreshChange(page) {
        this.getPage(this.page)
      }
    }
  }
</script>

<style lang="scss" scoped>
</style>
